<?php session_start();?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>WeCare : Add a File</title>
  </head>
  <body>
  
  <script type="text/javascript">

/**--------------------------
//* Validate Date Field script- By JavaScriptKit.com
//* For this script and 100s more, visit http://www.javascriptkit.com
//* This notice must stay intact for usage
---------------------------**/

function checkdate(input) //original de http://www.javascriptkit.com/script/script2/validatedate.shtml
{
	var validformat=/^\d{4}\-\d{2}\-\d{2}$/ //Basic check for format validity  YMD
	var returnval=false  

	if (!validformat.test(input.value))
		alert("Invalid Date Format. Please correct and submit again.")

	else{ //Detailed check for valid date ranges
		var monthfield=input.value.split("-")[1]
		var dayfield=input.value.split("-")[2]
		var yearfield=input.value.split("-")[0]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)
		
		
		
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
		else
			returnval=true
	}
	if (returnval==false) input.select()
	return returnval
}

function placeText()
{
    var seleccionado = getElementByIdCompatible("selDoc")
	var opcion = seleccionado.options[seleccionado.selectedIndex].value;
	var reemplazar = getElementByIdCompatible("author");
	reemplazar.text=opcion;
	reemplazar.value=opcion;
	
}

function getElementByIdCompatible (the_id) {  //http://www.webcodingtech.com/javascript/get-object-by-id-compatible.php
if (typeof the_id != 'string') {
return the_id;
}

if (typeof document.getElementById != 'undefined') {
return document.getElementById(the_id);
} else if (typeof document.all != 'undefined') {
return document.all[the_id];
} else if (typeof document.layers != 'undefined') {
return document.layers[the_id];
} else {
return null;
}
}

</script>
  
  <table width="100%" border="1" bordercolordark="#000000" cellpadding="0" cellspacing="0">
  <tr>
    <th background="images/bggen2.jpg"><span class="style1">Profile</span></th>
  </tr>
  <tr>
  <th>
    <form name="FileForm" action="fileScripts/controllers/addFile.php?id=<?php echo $_GET['id']; ?>" method="POST" enctype="multipart/form-data"
	 onSubmit="return checkdate(this.date)" >
      <div align="left">
       <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
		
		<tr>
			<td>
			</td>
		</tr>
		
		<tr> 
		<td width="246">
			<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
			<br/>
			Upload a File:
			<br/>
			FILE : &nbsp; <input name="userfile" type="file" id="userfile"> <br/>
            NAME : &nbsp; <input name="name" type="input" id="name"> <br/>
			Category/Type : &nbsp; <input name="cat" type="input" id="cat"> <br/>	
			Author : &nbsp; <input name="author" type="input" id="author"> <br/>
				 
				
				<?php
				    
					$query="SELECT userID FROM privileges WHERE patientID = '".$_GET['id']."' AND type = 'doctor'"; 
					include 'config.php';
					include 'fileScripts/controllers/dbOpenConn.php';
					$result=mysql_query($query) or die('Error Retrieving Doctors');
					if(mysql_num_rows($result) != 0) 
					{	
						
						echo "...or &nbsp; <select name=\"selDoc\" id=\"selDoc\" onChange=\"placeText()\"> 
							 <option value=\"\">-select a doctor-</option>";
						
						while(list($docId) = mysql_fetch_array($result))
						{
							$query = "SELECT patientID FROM privileges WHERE type='owner' AND userID='$docId'";
							$result2=mysql_query($query) or die('Error Retrieving Doctor data');
							$docDataId=mysql_result($result2,0,"patientID");
							$query = "SELECT name FROM patients WHERE id = '$docDataId'";
							$result2=mysql_query($query) or die('Error Retrieving Doctor data');
							$docName=mysql_result($result2,0,"name");							
				?>				
				
			                &nbsp;&nbsp;&nbsp; <option value="<?php echo $docName; ?>"><?php echo $docName; ?></option>
			                
				
				<?php   }   
						echo"</select> </br>";
						
					}
				//mysql_close();
				
					$query="SELECT id, concat(productName,\" : \",CCRDataObjectID) FROM problems WHERE patientID = '".$_GET['id']."'";
					$result=mysql_query($query) or die('Error Retrieving problems');
					if(mysql_num_rows($result) != 0) 
					{
				?>
			Relate to a Problem: &nbsp; <select name="problemSelect"> <option value="">select a problem</option>
			
				<?php 
					while(list($probId, $problem)=mysql_fetch_array($result))
					{
				?>
						<option value="<?= $probId?>" ><?= $problem ?></option>
				
				<?php		
					}
				?>
			
			
			</select><br/> 
			
				<?php } ?>
			
			Description : &nbsp; <input name="description" type="text" id="description"> <br/>	
			Date :  &nbsp;  <input name="date" type="input" id="date" placeholder="YYYY-MM-DD"> <br/>	
		</td>
		<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
		</tr>
	  </table>
      </div>
    </form>
  </th>
  </tr>
  </table>
  </body>
</html>